﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;

namespace NNTH
{
    public partial class fDangNhap : DevExpress.XtraEditors.XtraForm
    {
        public fDangNhap()
        {
            InitializeComponent();
        }

        Data.QLTTNNTHEntities db = new Data.QLTTNNTHEntities();
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (!db.DatabaseExists())
            {
                db.CreateDatabase();
                db.NhanVien.AddObject(
                    new Data.NhanVien()
                    {
                         Username="Admin",Password ="123456", HoTen="Nguyễn Thị Huê"
                    });
                db.SaveChanges();
            }
            if (textEdit1.EditValue!=null)
            {
                var te = textEdit1.EditValue.ToString();
                var pa = textEdit2.EditValue.ToString();
                if (db.NhanVien.Where(p=>p.Username==te && p.Password == pa).Any())
                {
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Sai mật khẩu hoặc tên đăng nhập!");
                }
            }
            else
            {
                MessageBox.Show("Nhập tên");
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}